package com.shiliu.api.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shiliu.api.mapper.TestUserMapper;
import com.shiliu.api.service.TestIUserService;
import com.shiliu.model.entity.TestUser;
import com.shiliu.model.pojo.PageResult;
import com.shiliu.model.pojo.ResponseResult;
import org.springframework.stereotype.Service;

import java.util.Objects;


/**
 * @description: 测试用户service实现类
 * @author: shili
 * @created: 2019/12/18 10:29
 * @version: v1.0.0
 */
@Service
public class TestUserServiceImpl extends ServiceImpl<TestUserMapper, TestUser> implements TestIUserService {
    @Override
    public ResponseResult queryByPage(Integer currentPage, Integer size, TestUser params) {

        Page<TestUser> page = new Page<>(currentPage,size);
        LambdaQueryWrapper<TestUser> wrapper = Wrappers.<TestUser>lambdaQuery();
        if(Objects.nonNull(params) && StringUtils.checkValNotNull(params.getName())){
            wrapper.like(TestUser::getName,params.getName());
        }
        IPage<TestUser> iPage = this.baseMapper.selectPage(page, wrapper);

        PageResult<TestUser> result = new PageResult<>();
        result.setRows(iPage.getRecords());
        result.setTotalPage(iPage.getPages());
        result.setTotalCount(iPage.getTotal());

        return ResponseResult.ok("查询成功!",10000,result);
    }
}
